<!--
 * @Descripttion: 
 * @version: 
 * @Author: 高月飞
 * @Date: 2023-11-19 14:01:10
 * @LastEditors: 高月飞
 * @LastEditTime: 2023-11-21 17:14:02
-->
<!--
 * @Descripttion: 
 * @version: 
 * @Author: 高月飞
 * @Date: 2023-11-19 14:01:10
 * @LastEditors: 高月飞
 * @LastEditTime: 2023-11-20 15:29:52
-->
<template>
    <div class="customerAll">
        <div class="allHeadvue">
            <div>
                <!-- 搜索 -->
                <allheadVue />
            </div>
            <div>
                <!-- 按钮 -->
                <allBtnVue @exposeCustomer="exposeCustomer" @importCustomer="importCustomer"
                    @shareCustomer="shareCustomer" />
            </div>
        </div>
        <div class="gap"></div>
        <div class="allTableVueStylus">
            <!-- 表格 -->
            <allTableVue :data="data" :total="total" :loadData="loadData" :page="page" :pageSize="pageSize" />
            <div class="gap"></div>
        </div>
        <div>
            <input ref="fileInputRef" type="file" style="display:none" @change="handleFileChange" />
        </div>
        <!-- 分享 -->
        <el-dialog v-model="dialogVisible" :show-close="false" :close-on-click-modal="false" id="shard" style="width:20%">
            <template #header="{ close, titleId }" style="100%">
                <div class="my-header">
                    <span :id="titleId">分享</span>
                    <el-icon @click="close" class="closestylus">
                        <Close />
                    </el-icon>
                </div>
            </template>
            <QRCode class="QRCode"> </QRCode>
        </el-dialog>

    </div>
</template>

<script setup lang="ts">

import allBtnVue from "./ui/allBtn.vue";
import allheadVue from "./ui/allhead.vue";
import allTableVue from "./ui/allTable.vue";
import { ElButton, ElDialog } from 'element-plus'
import { userDialogVisible, useCustomerList } from './subordinatehooks'
import { useRoute } from "vue-router";
import { reactive, ref } from "vue";
import type { ICustomerData } from "@/types/customer";
import { exposeCustomerDate } from "@/utils/Tools/exposeData";
import { readExcel } from "@/utils/Tools/inportData";
// 增加组件



interface IProps {
    page: number
    pageSize: number
}
const props = withDefaults(defineProps<IProps>(), {
    page: 1,
    pageSize: 10
})
const route = useRoute()
const [dialogVisible, setDialogVisible] = userDialogVisible()
const [data, total, loadData] = useCustomerList(props.page, route.query as object, props.pageSize)


//选中用户
const exportCustomerTable = reactive<any>([])
const onSelectData = (selectedData: ICustomerData.ICustomerList[]) => {
    selectedData.forEach(item => exportCustomerTable.push(item))
}
const customerHeader = reactive<object>({
    'id': 'id',
    "customername": "客户名称",
    "customersex": "性别",
    "customercontact": "联系人",
    "customerbirthday": "生日",
    "customerphone": "联系电话",
    "customerprofile": "客户简介",
    "customeremail": "联系邮箱",
    "customerarea": "所属地区",
    "customerposition": "公司职位",
    "creditcode": "信用代码",
    "customersource": "客户来源",
    "followupstatus": "跟进状态",
    "customerlevel": "客户等级",
    "followuptime": "跟进时间",
    "intentionalproduct": "意向产品",
    "founder": "创建者",
    "followupdepartment": "跟进部门",
    "remark": "备注"
})
// 导出客户
const exposeCustomer = (value: boolean) => {
    exposeCustomerDate(value, exportCustomerTable, customerHeader)
}
//导入数据
const fileInputRef = ref<HTMLInputElement | null>(null);
const tableData = ref<any>([]);
const importCustomer = (value: boolean) => {
    if (value) {
        if (fileInputRef.value) {
            fileInputRef.value.click();
        }
    }
}
const handleFileChange = (event: Event) => {
    const target = event.target as HTMLInputElement;
    const file = target.files?.[0];
    if (file) {
        readExcel(file, tableData)
    }
};
const shareCustomer = (value: boolean, item: string) => {
    if (item === "2") {
        dialogVisible.value = value
    }
}
</script>

<style lang="scss" scoped>
.customerAll {
    width: 100%;
    height: 100%;
    border-radius: 20px;



    .allHeadvue {
        margin-bottom: 5px;
        background-color: red;
        border-radius: 10px;

        div {
            height: 60px;
            background-color: #fff;
        }

    }

    .gap {
        height: 10px;
        background-color: #f2f2f2;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        border: 0;
    }

    .allTableVueStylus {
        width: 100%;
        margin-top: 5px;
        border-radius: 10px;
    }


}

.el-overlay {
    .el-overlay-dialog {
        .el-dialog {
            .el-dialog__body {
                .QRCode {
                    width: 100px;
                    height: 100px;
                    margin: auto;

                }
            }

            .el-dialog__header {
                width: 100%;
                margin: 0;
                padding: 0;
                height: 50px;
                display: flex;
                justify-content: space-between;
                align-items: center;
                background-color: red;

                .my-header {
                    width: 100%;
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                    text-align: center;

                    span {
                        width: 90%;
                        text-align: center;
                    }

                    i {
                        margin-right: 10px;
                    }


                }
            }
        }
    }

}

.closestylus {
    cursor: pointer;
}
</style>./subordinatehooks